<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-form :inline="true" :model="searchobj" class="tl" @submit.native.prevent>
          <el-form-item label="商品标题：">
            <el-input size="small" clearable v-model="searchobj.title" placeholder="请输入商品标题"></el-input>
          </el-form-item>
          <el-form-item label="活动场景：" v-if="types == 'product'">
            <el-select v-model="searchobj.types" size="small" clearable placeholder="请选择">
              <el-option v-for="(item, k) in activity_option" :key="k" :label="item" :value="k"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-row class="tl">
              <el-col :span="24">
                <el-button :loading="$store.state.isLoading" size="small" class="top_weiy" type="primary" @click="onSearch">查询</el-button>
                <el-button :loading="$store.state.isLoading" size="small" class="top_weiy" type="primary" @click="delSearch">一键清除</el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-table :data="shoplist.data" stripe header-row-class-name="head_color" tooltip-effect="dark" style="width: 99.9%">
      <!-- <el-table-column label="图片" min-width="120">
        <template slot-scope="scope"><img style="width: 100px" :src="$fnc.getImgUrl(scope.row.piclink)" alt="" /></template>
      </el-table-column> -->
      <el-table-column label="商品信息" min-width="250">
        <template slot-scope="scope">
          <el-popover placement="right" title trigger="hover">
            <img :src="scope.row.piclink" style="width: 300px" />

            <div class="tab_div" slot="reference">
              <div>
                <span>商品名称：</span>
                <span>{{ scope.row.title || "----" }}</span>
              </div>
              <div>
                <span>商品类别：</span>
                <span>{{ scope.row.cate_title || "----" }}</span>
              </div>
              <div v-if="scope.row.label && scope.row.label.length > 0">
                <el-tag v-for="(label, l) in scope.row.label" style="margin-right: 5px; color: #ffffff; margin-left: 0" size="mini" :key="l" effect="dark">{{ label }}</el-tag>
              </div>
            </div>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column label="价格信息" min-width="150">
        <template slot-scope="scope">
          <div class="tab_div">
            <div>
              <span>售价：</span>
              <span>{{ scope.row.price || "----" }}</span>
            </div>
            <div>
              <span>成本价：</span>
              <span>{{ scope.row.cost_price || "----" }}</span>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="属性" min-width="150">
        <template slot-scope="scope">
          <div class="tab_div">
            <div>
              <span>商品类别：</span>
              <span>{{ scope.row.cate_title || "----" }}</span>
            </div>
            <div>
              <span>浏览量：</span>
              <span>{{ scope.row.views }}</span>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="属性" min-width="120">
        <template slot-scope="scope">
          <div class="tab_div">
            <div>
              <span>真实销量：</span>
              <span>{{ scope.row.real_sale }}</span>
            </div>
            <div>
              <span>库存总量：</span>
              <span>{{ scope.row.stock }}</span>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="120">
        <template slot-scope="scope">
          <el-button :loading="$store.state.isLoading" size="mini" type="primary" @click="addShops(scope.row)">确认选择</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row>
      <el-col :span="24" class="table_bottom">
        <el-col :span="24" class="tr">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage1"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="shoplist.all_num"
          >
          </el-pagination>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  name: "xzShop",
  components: {},
  props: {
    show: {
      type: Boolean,
    },
    types: {
      type: String,
      default: "",
    },
    data: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      searchobj: {
        types: "",
        title: "",
      },
      shoplist: {},
      currentPage1: 1,
      pageSize: 10,
      loading: false,
      activity_option: [],
    };
  },
  created() {
    this.get_activity_option();
  },
  methods: {
    get_activity_option() {
      this.$api.getShops.get_activitylist({}).then((res) => {
        if (res.data.code == 200) {
          this.activity_option = res.data.result;
        }
      });
    },
    delSearch() {
      this.searchobj = {
        types: "",
        title: "",
      };
      this.get_shoplist(1);
    },
    onSearch() {
      this.get_shoplist(1);
    },
    get_shoplist(page) {
      var type, is_supplier;
      var model = "getShopsList"; //get_courselist
      var active = this.types;
      console.log(active);
      if (active == "spike") {
        type = 7;
      } else if (active == "presale") {
        type = 6;
      } else if (active == "group") {
        type = 4;
      } else if (active == "knowledge") {
        model = "get_courselist";
      } else if (active == "tour") {
        type = 9;
      } else if (active == "together") {
        type = 19;
      } else if (active == "auction") {
        type = 18;
      } else if (active == "rgoods") {
        type = 13;
      } else if (active == "rservice") {
        type = 14;
      } else if (active == "product") {
        is_supplier = 2;
      } else if (active == "lyg") {
        type = 24; //零元购
      } else if (active == "bargain") {
        type = 3; //零元购
      }
      // else if(active == "audio"){
      //   type = 22;//音频课程
      // }else if(active == "fiction"){
      //   type = 23;//小说书籍
      // }

      var params = {};
      params = this.searchobj;
      params.page = page;
      params.page_size = this.pageSize;
      if (type && active != "product") {
        params.types = type;
      }
      params.is_supplier = is_supplier;
      params.show = 1;
      params.is_check = 1;
      this.$api.getShops[model](params).then((res) => {
        if (res.data.code == 200) {
          this.shoplist = res.data.result;
        } else {
          this.$fnc.alerterror(res.data.result);
        }
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage1 = 1;
      this.get_shoplist(1);
    },
    handleCurrentChange(val) {
      this.get_shoplist(val);
    },
    addShops(row) {
      console.log(row);
      row.url_title = "商品选择";
      this.$emit("sendShop", row);
    },

    closeDio() {
      this.$emit("isshow", false);
    },
  },
  watch: {
    show(old, after) {
      if (old == true) {
        this.currentPage1 = 1;
        this.pageSize = 10;
        this.get_shoplist(1);
      }
    },
  },
  computed: {},
  mounted() {},
};
</script>
<style lang="less" scoped>
.list_ul {
  overflow: auto;
}
.list_card {
  padding: 15px;
  cursor: pointer;
}
.card_list {
  line-height: 2;
  padding: 5px 0 0 5px;
}
.price_card {
  color: red;
}
.image {
  height: 200px;
  max-width: none;
  max-height: none;
}
</style>
